﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//importamos
using System.Data.Entity.ModelConfiguration;
using CredisysTriunfadores.BusinessEntites.Prestamos;
using System.ComponentModel.DataAnnotations.Schema;

namespace CredisysTriunfadores.Repository.Mapping
{
    public class CuotaPagoMap:EntityTypeConfiguration<CuotaPago>
    {
        public CuotaPagoMap()
        {
            //clave primaria y que sea autoincremental
            this.HasKey(cp => cp.Id);
            this.Property(cp => cp.Id)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

            //propiedades
            this.Property(cp => cp.Estado)
                .HasColumnType("varchar")
                .HasMaxLength(20)
                .IsRequired();
            this.Property(cp => cp.Interes)
                .HasColumnType("decimal")
                .HasPrecision(9, 2)
                .IsRequired();
            this.Property(cp => cp.FechaPago)
                .HasColumnType("datetime2")
                .IsRequired();
            this.Property(cp => cp.Monto)
                .HasColumnType("decimal")
                .HasPrecision(9, 2)
                .IsRequired();

            //relaciones
            this.HasRequired(cp=>cp.Prestamo)
                .WithMany(cp=>cp.IcCuotasPagoPrestamo)
                .HasForeignKey(cp=>cp.IdPrestamo)
                .WillCascadeOnDelete(false);

        }
    }
}
